<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Video;
use Carbon\Carbon;
use \Cache;

class VideoController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function list(Request $request)
    {
        $this->validate($request, [
            'category_id' => 'nullable|numeric',//分类id
            'id' => 'nullable|numeric',//分类id
        ]);

        $banner = Video::when($request->get('category_id'),function ($query){
            return $query->where('category_id', request('category_id'));
        })
            ->when($request->get('id'),function ($query){
                return $query->where('id', request('id'));
            })
            ->orderBy('sort')
            ->paginate(15);

        return $this->successReturn($banner);
    }


}
